package com.pethome.web.controller;

import com.pethome.common.annotation.Log;
import com.pethome.common.core.controller.BaseController;
import com.pethome.common.core.domain.AjaxResult;
import com.pethome.common.core.page.TableDataInfo;
import com.pethome.common.enums.BusinessType;
import com.pethome.common.utils.poi.ExcelUtil;
import com.pethome.web.domain.Visit;
import com.pethome.web.service.IVisitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 回访信息Controller
 * 
 * @author hjc
 * @date 2024-08-26
 */
@RestController
@RequestMapping("/web/visit")
public class VisitController extends BaseController
{
    @Autowired
    private IVisitService visitService;

    /**
     * 查询回访信息列表
     */
    @PreAuthorize("@ss.hasPermi('web:visit:list')")
    @GetMapping("/list")
    public TableDataInfo list(Visit visit)
    {
        startPage();
        List<Visit> list = visitService.selectVisitList(visit);
        return getDataTable(list);
    }

    /**
     * 导出回访信息列表
     */
    @PreAuthorize("@ss.hasPermi('web:visit:export')")
    @Log(title = "回访信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Visit visit)
    {
        List<Visit> list = visitService.selectVisitList(visit);
        ExcelUtil<Visit> util = new ExcelUtil<Visit>(Visit.class);
        util.exportExcel(response, list, "回访信息数据");
    }

    /**
     * 获取回访信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('web:visit:query')")
    @GetMapping(value = "/{visitId}")
    public AjaxResult getInfo(@PathVariable("visitId") Long visitId)
    {
        return success(visitService.selectVisitByVisitId(visitId));
    }

    /**
     * 新增回访信息
     */
    @PreAuthorize("@ss.hasPermi('web:visit:add')")
    @Log(title = "回访信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Visit visit)
    {
        return toAjax(visitService.insertVisit(visit));
    }

    /**
     * 修改回访信息
     */
    @PreAuthorize("@ss.hasPermi('web:visit:edit')")
    @Log(title = "回访信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Visit visit)
    {
        return toAjax(visitService.updateVisit(visit));
    }

    /**
     * 删除回访信息
     */
    @PreAuthorize("@ss.hasPermi('web:visit:remove')")
    @Log(title = "回访信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitIds}")
    public AjaxResult remove(@PathVariable Long[] visitIds)
    {
        return toAjax(visitService.deleteVisitByVisitIds(visitIds));
    }
}
